package com.itcast.n9_垃圾回收;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;

/**
 * @program: jvm
 * @description: -XX:+TraceClassLoading -XX:+TraceClassUnloading
 * @author: flyduck
 * @create: 2024-09-23 15:38
 **/
public class Test04_类回收失败原因3_此类对应Class对象被引用 {
    public static void main(String[] args) throws InterruptedException {

        try {
            ArrayList<Class<?>> classes = new ArrayList<>();
            ArrayList<URLClassLoader> loaders = new ArrayList<>();
            ArrayList<Object> objs = new ArrayList<>();
            while (true) {

                URLClassLoader loader = new URLClassLoader(
                new URL[]{new URL("file:E:\\code\\flyduck-note\\jvm\\test\\")});
                Class<?> clazz = loader.loadClass("com.itcast.my.C");
                Object o = clazz.newInstance();
                classes.add(clazz);
                System.gc();

            }


        } catch (Exception e) {

            e.printStackTrace();
        }
    }
}
